package com.yitongmao.util;

import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.util.DisplayMetrics;
import android.view.View;
import android.webkit.CookieManager;

import com.yitongmao.common.reminder.ReaderApplication;


public class UIUtils {

    public static final String intentKey = "className";
    public static final String intentData = "data";
    public static String intentCode = "code";

    /**
     * dip转换px
     */
    public static int dip2px(int dip) {
        final float scale = getContext().getResources().getDisplayMetrics().density;
        return (int) (dip * scale + 0.5f);
    }

    /**
     * pxz转换dip
     */

    public static int px2dip(int px) {
        final float scale = getContext().getResources().getDisplayMetrics().density;
        return (int) (px / scale + 0.5f);
    }

    /**
     * 根据资源id 获取字符串数组
     *
     * @param id
     * @return
     */
    public static String[] getStringArray(int id) {
        return getResources().getStringArray(id);
    }

    /**
     * 获取Resources对象
     *
     * @return
     */
    public static Resources getResources() {
        return getContext().getResources();
    }
    /**
     * 获取上下文对象
     *
     * @return
     */
    public static Context getContext() {
        return ReaderApplication.getInstace();
    }


    /**
     * xml --->View对象
     *
     * @param id
     * @return
     */
    public static View inflate(int id) {
        return View.inflate(UIUtils.getContext(), id, null);
    }

    /**
     * 获取屏幕密度
     */
    public static int getDenisty(Activity activity) {
        //        获取屏幕密度
        DisplayMetrics metric = new DisplayMetrics();
        activity.getWindowManager().getDefaultDisplay().getMetrics(metric);
        return metric.densityDpi;
    }


    /**
     * 获取key3
     *
     * @param key3
     * @return
     */
    public static String getkey(int key3) {
        return getString(key3);
    }
    public static String getString(int id) {
        return getResources().getString(id);
    }
    /**
     * 获取Cookie值
     *
     * @param url
     * @return
     */
    public static String getCookie(String url) {
        CookieManager instance = CookieManager.getInstance();
        return instance.getCookie(url);
    }
}
